
const Service = require('egg').Service;

class nezaService extends Service {
  constructor() {
    super(...arguments);
    /**
     *@abstract 初始化连接的数据库 db1
    */
    this.client1 = this.app.mysql.get('db1');

    this.tableName = 'tx_signupnezha';
  }
  /**
	* @param param 报名参数
	*/
  async send(param) {
    const { ctx } = this;
    const {
      name,
      phone,
      dealer_id,
      series,
      voId,
      fromSystem,
      cusSource3,
    } = param;
    const timestamp = Math.floor(new Date().getTime() / 1000);
    try {
      const insertData = {
        name,
        phone,
        dealer_id,
        series,
        voId,
        fromSystem,
        cusSource3,
        createtime: timestamp,
      };
      const { createDb } = ctx.helper;
      const result = await createDb(this.client1, this.tableName, insertData);
      if (result.affectedRows === 1) {
        ctx.getLogger('bmLogger').info('bm success', insertData);
        return {
          code: 200,
          message: 'success',
          data: insertData,
        };
      }
      return {
        code: 500,
        message: '报名失败',
      };
    } catch (error) {
      throw new Error(`报名失败 ${error}`);
    }
  }
}


module.exports = nezaService;
